<script setup lang="ts">
// 定义 props
defineProps<{
  name: string
  title: string
  avatar?: string
  userId: number
}>()

// 定义 emit 事件， 往外暴露 select 事件
const emit = defineEmits<{
  select: [userId: number]
}>()
</script>

<template>
  <div class="user-card" @click="emit('select', userId)">
    <img 
      :src="avatar || 'https://via.placeholder.com/50'" 
      :alt="name"
      class="avatar"
    >
    <div class="info">
      <h3>{{ name }}</h3>
      <p>{{ title }}</p>
    </div>
    <slot name="title"></slot>
    <slot>22</slot>
  </div>
</template>

<style scoped>
.user-card {
  display: flex;
  align-items: center;
  padding: 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
}

.avatar {
  width: 50px;
  height: 50px;
  border-radius: 25px;
  margin-right: 1rem;
}

.info h3 {
  margin: 0;
  font-size: 1.1em;
}

.info p {
  margin: 0.5em 0 0;
  color: #666;
}
</style> 